//
//  DoorTabBarViewController.m
//  RONGAO
//
//  Created by wei wang on 2017/2/23.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "DoorTabBarViewController.h"
/*
#import "DoorHomeViewController.h"
#import "DoorUserViewController.h"
#import "DoorEnginerViewController.h"
*/

#define TheTabNorDarkColor [UIColor colorWithHexString:@"#6c6861"]
#define TheTabSelDarkColor [UIColor colorWithHexString:@"#dab866"]

@interface DoorTabBarViewController ()
@property (strong, nonatomic) NSMutableArray *btnList;

@end

@implementation DoorTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupTabBarBtn];
    [self setSelectedIndex:1];
    UIButton *btn = self.btnList[1];
    [self buttonAction:btn];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backVC) name:@"DisConnect" object:nil];
}

- (void)backVC{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)setupTabBarBtn{
    
    
   /*
    DoorEnginerViewController *firstVC = [[DoorEnginerViewController alloc]init];
    UINavigationController *naFirst = [[UINavigationController alloc]initWithRootViewController:firstVC];
    
    
   
    DoorHomeViewController *secondVC = [[DoorHomeViewController alloc]init];
    UINavigationController *naSecond = [[UINavigationController alloc]initWithRootViewController:secondVC];
    
    
   
    DoorUserViewController *thirdVC = [[DoorUserViewController alloc]init];
    UINavigationController *naThird = [[UINavigationController alloc]initWithRootViewController:thirdVC];

    [self setViewControllers:@[naFirst,naSecond,naThird]];

    NSArray *norImageArray = @[@"icon_engineering_nor",@"icon_home_nor",@"icon_user_nor"];
    NSArray *selImageArray = @[@"icon_engineering_sel",@"icon_home_sel",@"icon_user_sel"];
    NSArray *titleArray = @[@"工程",@"主页",@"用户"];

    UIView *tabBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49)];
    tabBar.backgroundColor = [UIColor colorWithHexString:@"#231815"];
    
    for (int i = 0; i < norImageArray.count; i++) {
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(i*SCREEN_WIDTH/norImageArray.count, 0, SCREEN_WIDTH/norImageArray.count, TabBarHeight)];
        [button setImage:[UIImage imageNamed:selImageArray[i]] forState:UIControlStateSelected];
        [button setImage:[UIImage imageNamed:norImageArray[i]] forState:UIControlStateNormal];
        [button setTitle:titleArray[i] forState:UIControlStateNormal];
        [button setTitleColor:TheTabNorDarkColor forState:UIControlStateNormal];
        [button setTitleColor:TheTabSelDarkColor forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageNamed:@"button_selected-"] forState:UIControlStateSelected];
//        [button setBackgroundImage:[UIImage imageNamed:@"tab_bg"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12.f];
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:3.f];
        [tabBar addSubview:button];
        
        button.tag = 10 + i;
        button.selected = (0 == i)?YES:NO;
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.btnList addObject:button];
    }
    
    [self hideBottomHairline];
    [self.tabBar addSubview:tabBar];
*/
    
}

- (NSMutableArray *)btnList
{
    if (!_btnList) {
        _btnList = [[NSMutableArray alloc]init];
    }
    return _btnList;
}

- (void)hideBottomHairline {
    UIImageView *navBarHairlineImageView = [self findHairlineImageViewUnder:self.tabBar];
    navBarHairlineImageView.hidden = YES;
}

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

- (void)buttonArray:(NSInteger)index{
    
    UIButton *btn = self.btnList[1];
    [self buttonAction:btn];
}

- (void)buttonAction:(UIButton *)sender
{
    self.selectedIndex = sender.tag - 10;
    for (UIButton *btn in self.btnList) {
        btn.selected = NO;
    }
    sender.selected = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
